<?php
/**
 * 一元包邮专区专用
 */

/**
 * 监测是否可以购买
 */
function isBuyone() {
    include_once(ROOT_PATH . 'includes/classCounter.php');
    $c = new classCounter();
    // 如果已经标记为不可购买，则直接返回false;
    if (!empty($_SESSION['isNoBuyone_']) || M()->get('isNoBuyone_' . $_SESSION['user_id'])) {
        return false;
    } elseif (!empty($_SESSION['isBuyone_']) || M()->get('isBuyone_' . $_SESSION['user_id'])) {
        return true;
    } else {
        M()->increment('sumBuyoneUserNum', rand(2,5));
        M()->increment('sumBuyoneUserNum2');
        // 查询分流是否满人，并标记是否可抢购
        if ($c->deCounter('setSumBuyone')) {
            M()->add('isBuyone_' . $_SESSION['user_id'], '1', 86400);
            $_SESSION['isBuyone_'] = 1;
            return true;
        } else {
            M()->add('isNoBuyone_' . $_SESSION['user_id'], '1', 86400);
            $_SESSION['isNoBuyone_'] = 1;
            return false;
        }
    }
}

/**
 * 获取一元包邮列表
 */
function getBuyoneList() {
    // $sql = "SELECT a.parent_id, a.name, a.img, a.price, a.original_price FROM {$GLOBALS['db']->table('activity')} a WHERE a.is_sale = 1 AND a.extension_code = 'buyone' AND a.parent_id = 95";
    // $list = $GLOBALS['db']->getAll($sql);
    // if (!empty($list)) {
    //     foreach ($list as $key => $value) {
    //         $list[$key]['img'] = getUrl('activity_img', $value['img']);
    //     }
    // }
    $list = Array
        (
            111 => Array
                (
                    'parent_id' => '111',
                    'name' => '雪山·素描本-8.5x11(无圈)',
                    'img' => '//www.eggms.com/images/201509/1442540829300564594.jpg',
                    'price' => '1.00',
                    'original_price' => '15.90',
                    'start_time' => strtotime('2015-09-18 22:00:00'),
                    'end_time' => strtotime('2015-09-19 22:00:00'),
                    'start_date' => '09月18日22:00',
                    'end_date' => '09月19日22:00',
                    'stock' => '67'
                ),
            100 => Array
                (
                    'parent_id' => '100',
                    'name' => 'LYRA（艺雅）· Osiris三角杆水溶性彩色铅笔-12色',
                    'img' => '//www.eggms.com/images/201509/1441187905990599702.jpg',
                    'price' => '1.00',
                    'original_price' => '34.90',
                    'start_time' => strtotime('2015-09-18 22:00:00'),
                    'end_time' => strtotime('2015-09-19 22:00:00'),
                    'start_date' => '09月18日22:00',
                    'end_date' => '09月19日22:00',
                    'stock' => '7'
                ),
            99 => Array
                (
                    'parent_id' => '99',
                    'name' => '高尔乐·初学素描套装',
                    'img' => '//www.eggms.com/images/201508/1440746757972243949.jpg',
                    'price' => '1.00',
                    'original_price' => '35.00',
                    'start_time' => strtotime('2015-09-18 22:00:00'),
                    'end_time' => strtotime('2015-09-19 22:00:00'),
                    'start_date' => '09月18日22:00',
                    'end_date' => '09月19日22:00',
                    'stock' => '20'
                ),
            95 => Array
                (
                    'parent_id' => '95',
                    'name' => '石氏毕加索·初学者全能画笔套装-8支(盒)',
                    'img' => '//www.eggms.com/images/201508/1440141353990759614.jpg',
                    'price' => '1.00',
                    'original_price' => '36.50',
                    'start_time' => strtotime('2015-09-18 22:00:00'),
                    'end_time' => strtotime('2015-09-19 22:00:00'),
                    'start_date' => '09月18日22:00',
                    'end_date' => '09月19日22:00',
                    'stock' => '20'
                ),
            90 => Array
                (
                    'parent_id' => '90',
                    'name' => '方舟·电动橡皮-蓝色（卡）',
                    'img' => '//www.eggms.com/images/201508/1439259314238785741.jpg',
                    'price' => '1.00',
                    'original_price' => '28.00',
                    'start_time' => strtotime('2015-09-18 22:00:00'),
                    'end_time' => strtotime('2015-09-19 22:00:00'),
                    'start_date' => '09月18日22:00',
                    'end_date' => '09月19日22:00',
                    'stock' => '20'
                ),
        );
    return $list;
    }